package com.aios.action.user.iris;

import com.aios.action.ISortColumn;
import com.aios.util.DataManipulator;

public class IrisUserSearchAction extends AbstractIrisUserAction implements
		ISortColumn {

	private static final long serialVersionUID = 1L;

	private static final String Name = "NAME";
	private static final String EmployeeID = "EMPLOYEE_ID";

	private String searchTerm;

	public String execute() {

		DataManipulator manipulator = new DataManipulator();

		if (getManipulatorSessionVariable() != null) {
			manipulator = getManipulatorSessionVariable();
		} else {

			manipulator.setSortBy(getDefaultSortColumn());
			manipulator.setSortOrder(getDefaultSortColumn());
			manipulator.setDataType("iris_user");
		}
		
		if(searchTerm==null && manipulator.hasSearchParam()) {
			searchTerm = manipulator.getSearchParamMap().get("NAME");
		}

		manipulator.clearSearchParam();
		manipulator.addSearchParam(Name, searchTerm);
		manipulator.addSearchParam(EmployeeID, searchTerm);

		addManipulatorSessionVariable(manipulator);

		pager = irisUserService.viewPaginatedSearchList(pageStart, pageSize,
				manipulator);

		pager = setActionContext(pager);

		return SUCCESS;
	}

	public String getSearchTerm() {
		return searchTerm;
	}

	public void setSearchTerm(String searchTerm) {
		this.searchTerm = searchTerm;
	}

	@Override
	public String getDefaultSortColumn() {
		return "EMPLOYEE_ID";
	}

	@Override
	public String getDefaultSortOrder() {
		return "ASC";
	}

}
